package com.aw.baselib.util

import com.aw.baselib.util.AwDataUtil.isEmpty
import com.aw.baselib.util.SPUtils.put

/**
 * @author : hzw
 * @date : 2020/3/18
 */
object UserUtil {
    fun saveAccount(account: String?) {
        put("account", account!!)
    }

    val account: String?
        get() = SPUtils["account", ""] as String?

    fun savePwd(pwd: String?) {
        put("pwd", pwd!!)
    }

    val pwd: String?
        get() = SPUtils["pwd", ""] as String?

    fun saveVin(vin: String?) {
        put("vin", vin!!)
    }

    val vin: String?
        get() = SPUtils["vin", ""] as String?

    fun saveUserLat(lat: String?) {
        put("userLat", lat!!)
    }

    val userLat: String?
        get() =//默认天安门纬度
            SPUtils["userLat", "39.915119"] as String?

    fun saveUserLng(lng: String?) {
        put("userLng", lng!!)
    }

    val userLng: String?
        get() =//默认天安门经度
            SPUtils["userLng", "116.403963"] as String?

    fun saveUserAddress(address: String?) {
        put("userAddress", address!!)
    }

    val userAddress: String?
        get() = SPUtils["userAddress", ""] as String?

    fun savePhone(param: String?) {
        var param = param
        if (isEmpty(param)) {
            param = "13921131093"
        }
        put("phone", param!!)
    }

    val phone: String?
        get() = SPUtils["phone", "13921131093"] as String?

    fun clearUser() {
        put("user", "")
        put("token", "")
        put("warehouse", "")
    }

    fun saveToken(token: String?) {
        put("token", token!!)
    }

    @JvmStatic
    val token: String
        get() = if (!isEmpty(
                SPUtils["token", ""] as String?
            )
        ) {
            "Bearer " + SPUtils["token", ""]
        } else {
            ""
        }
    var isFirstUse: Boolean
        get() = SPUtils["isFirstUse", true] as Boolean
        set(isFirstUse) {
            put("isFirstUse", isFirstUse)
        }
    var isAgreePrivacy: Boolean
        get() = SPUtils["isAgreePrivacy", false] as Boolean
        set(isFirstUse) {
            put("isAgreePrivacy", isFirstUse)
        }

    /**
     * 登录记住密码
     * @param phone
     * @param password
     */
    fun loginRememberToSave(phone: String?, password: String?, isRemember: Boolean) {
        put("rememberPassword", isRemember)
        put("phone", phone!!)
        if (isRemember) {
            put("password", password!!)
        }
    }

    /**
     * 退出登录等清除本地保存的记录.
     */
    fun cleanLocalSaveAccountAndPwd() {
        put("phone", "")
        put("password", "")
    }

    val rememberPhone: String?
        get() = SPUtils["phone", ""] as String?
    val rememberPwd: String?
        get() = SPUtils["password", ""] as String?
    val isRemeberLogin: Boolean
        get() = SPUtils["rememberPassword", false] as Boolean
}